package com.inspur.gs.sbssdl.sbssgl.sbtz.sbtz.back.sbsssbtz.common;

import com.inspur.edp.bef.api.lcp.IStandardLcp;
import com.inspur.edp.bef.core.LcpUtil;
import com.inspur.edp.bef.engine.entity.AssociationInfo;
import com.inspur.edp.cef.entity.changeset.ModifyChangeDetail;
import com.inspur.edp.cef.entity.entity.IEntityData;

import java.util.ArrayList;

public class SbssSbtzLogUtils {

    public static String SbtzConfig = "com.inspur.gs.sbssdl.sbssgl.sbtz.sbtz.back.SbssSbtz";

    public static void changelog(String tzId,String DataName,String DataComm,String oldValue,String updValue,String valueFrom,String changeUser) {
        IStandardLcp sbtzLcp = LcpUtil.getLcp(SbtzConfig);
        if (sbtzLcp == null) {
            return;
        }

        // 添加日志信息
        ModifyChangeDetail curChange = new ModifyChangeDetail(tzId);
        ArrayList<String> nodeCodes = new ArrayList<>();
        nodeCodes.add("SBSS_SBTZ_CHANGELOG");
        ArrayList<String> hierarchyIds = new ArrayList<>();
        hierarchyIds.add(tzId);
        IEntityData log = sbtzLcp.retrieveDefaultChild(nodeCodes, hierarchyIds);

        ModifyChangeDetail childChange = new ModifyChangeDetail(log.getID());

        childChange.getPropertyChanges().put("DataName", DataName);
        childChange.getPropertyChanges().put("DataComm", DataComm);
        childChange.getPropertyChanges().put("oldValue", oldValue);
        childChange.getPropertyChanges().put("updValue", updValue);
        childChange.getPropertyChanges().put("valueFrom", valueFrom);

        AssociationInfo changeUserInfo = new AssociationInfo();
        changeUserInfo.setValue("changeUser",changeUser);
        childChange.getPropertyChanges().put("changeUser", changeUserInfo);

        curChange.addChildChangeSet("SBSS_SBTZ_CHANGELOG", childChange);

        sbtzLcp.modify(curChange);
        sbtzLcp.save();
    }

}
